#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int minNumberOfFrogs(string croakOfFrogs) {
    string t = "croak";
    int n = t.size();
    unordered_map<char, int> index;
    vector<int> count(n, 0);

    for (int i = 0; i < n; ++i)
    {
        index[t[i]] = i;
    }

    for (auto ch : croakOfFrogs)
    {
        if (ch == 'c')
        {
            if (count[n - 1] != 0)
            {
                count[n - 1]--;
                count[index[ch]]++;
            }
            else
            {
                count[index[ch]]++;
            }
        }
        else
        {
            if (count[index[ch] - 1] == 0)  return -1;
            count[index[ch] - 1]--;
            count[index[ch]]++;
        }
    }

    for (int i = 0; i < n - 1; ++i)
    {
        if (count[i] != 0)  return -1;
    }

    return count[n - 1];
}

int main()
{
    minNumberOfFrogs("croakcroak");
	return 0;
}